home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_glimpse.idb / usr / freeware / src / glimpse-3.0 / libtemplate / util / string.c.z / string.c
C/C++ Source or Header  |  1997-09-09  |  3KB  |  101 lines

  1. static char rcsid[] = "$Id: string.c,v 1.7 1995/01/10 16:31:10 hardy Exp $";
  2. /*
  3.  *  string.c - Simple string manipulation 
  4.  *
  5.  *  Darren Hardy, hardy@cs.colorado.edu, June 1994
  6.  *
  7.  *  ----------------------------------------------------------------------
  8.  *  Copyright (c) 1994, 1995.  All rights reserved.
  9.  *  
  10.  *          Mic Bowman of Transarc Corporation.
  11.  *          Peter Danzig of the University of Southern California.
  12.  *          Darren R. Hardy of the University of Colorado at Boulder.
  13.  *          Udi Manber of the University of Arizona.
  14.  *          Michael F. Schwartz of the University of Colorado at Boulder. 
  15.  *  
  16.  *  This copyright notice applies to all code in Harvest other than
  17.  *  subsystems developed elsewhere, which contain other copyright notices
  18.  *  in their source text.
  19.  *  
  20.  *  The Harvest software was developed by the Internet Research Task
  21.  *  Force Research Group on Resource Discovery (IRTF-RD).  The Harvest
  22.  *  software may be used for academic, research, government, and internal
  23.  *  business purposes without charge.  If you wish to sell or distribute
  24.  *  the Harvest software to commercial clients or partners, you must
  25.  *  license the software.  See
  26.  *  http://harvest.cs.colorado.edu/harvest/copyright,licensing.html#licensing.
  27.  *  
  28.  *  The Harvest software is provided ``as is'', without express or
  29.  *  implied warranty, and with no support nor obligation to assist in its
  30.  *  use, correction, modification or enhancement.  We assume no liability
  31.  *  with respect to the infringement of copyrights, trade secrets, or any
  32.  *  patents, and are not responsible for consequential damages.  Proper
  33.  *  use of the Harvest software is entirely the responsibility of the user.
  34.  *  
  35.  *  For those who are using Harvest for non-commercial purposes, you may
  36.  *  make derivative works, subject to the following constraints:
  37.  *  
  38.  *  - You must include the above copyright notice and these accompanying 
  39.  *    paragraphs in all forms of derivative works, and any documentation 
  40.  *    and other materials related to such distribution and use acknowledge 
  41.  *    that the software was developed at the above institutions.
  42.  *  
  43.  *  - You must notify IRTF-RD regarding your distribution of the 
  44.  *    derivative work.
  45.  *  
  46.  *  - You must clearly notify users that your are distributing a modified 
  47.  *    version and not the original Harvest software.
  48.  *  
  49.  *  - Any derivative product is also subject to the restrictions of the 
  50.  *    copyright, including distribution and use limitations.
  51.  */
  52. #include <stdio.h>
  53. #include <string.h>
  54. #include <ctype.h>
  55. #include "util.h"
  56.  
  57. #ifndef isquote
  58. #define isquote(c)    (((c) == '\"') || ((c) == '\''))
  59. #endif
  60.  
  61. /*
  62.  *  parse_argv() - Parses the command string to build an argv list.  
  63.  *  Supports simple quoting.  argv is large enough to support the 
  64.  *  command string.
  65.  */
  66. void parse_argv(argv, cmd)
  67. char *argv[];
  68. char *cmd;
  69. {
  70.     char *tmp, *p, *q;
  71.     int i = 0;
  72.  
  73.     p = q = tmp = strdup(cmd);
  74.     while (1) {
  75.         if (isquote(*q)) {
  76.             p++;
  77.             q++;
  78.             while (*q && !isquote(*q))
  79.                 q++;
  80.             if (isquote(*q))
  81.                 *q++ = '\0';
  82.             else if (*q == '\0')
  83.                 break;
  84.         } else {
  85.             while (*q && !isspace(*q))
  86.                 q++;
  87.         }
  88.         while (isspace(*q) && !isquote(*q))
  89.             *q++ = '\0';
  90.         if (*q == '\0') {
  91.             argv[i++] = strdup(p);
  92.             break;
  93.         }
  94.         if (*p)
  95.             argv[i++] = strdup(p);
  96.         p = q;
  97.     }
  98.     argv[i] = NULL;
  99.     xfree(tmp);
  100. }
  101.